;(function($, window, document, undefined) {
	if (!window.console) {
		  window.console = window.console || (function() {
		    var c = {};
		    c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function() {};
		    return c;
		  })();
		}
  //创建科目导航tab
	function createSubjectDiv(settings){
		var subjects = OBT.paper.getSubjects();
		var len = subjects.count;
		//单科目无需tab
		if(len <= 1)
			return;
		//当前试卷
		var po = OBT.paper.getCurPaper();
		var $subul = $('<div id="subjecttab"><ul class="ul-subject"></ul></div>');
		for(var i=0;i< len;i++){
			var $subtab = $('<li><a href="#'+subjects.data[i].paperCode+'">'+subjects.data[i].name+'</a></li>');
			//当前tab
			if(po.code == subjects.data[i].paperCode)
				$subtab.toggleClass('active',true);
			//绑定科目切换事件
			$subtab.children('a').bind("click",subjects.data[i].paperCode,function(e) {
				if(e.data == OBT.paper.getCurPaper().code)
					return;
				//发布当前试卷更改事件
				//$.publish(OBT.EVENT_PAPER_CHANGING,[e.data]);
			});
			//补充到ul中
			//$subul.children('ul').append($subtab);
		}
		return $subul;
	}
	//创建试卷导航DIV
	function createPaperDiv(settings,type){
		var papers = OBT.paper.getPapers();
		
		console.log(papers);
		
		var len = papers.count;
		//当前试卷
		var curpo = OBT.paper.getCurPaper();
		//作答进度
		var progress = OBT.paper.getProgress();

		var $pdiv = $('<div id="papernav"></div>');
		for(var i=0;i< len;i++){
			//试卷对象
			var po = papers.data[i];
			
			//试卷分组
			var $pul = $('<ul id="P-'+po.code+'"></ul>');
			var $itdiv = $('<div class="subitem"></div>');
			//当前试卷显示
			if(po.code == curpo.code){
				$pul.show();
			}else{
				$pul.hide();
			}
			//设置链接标题
			console.log(po);
			var firstTitle = po.groups[0].name.substring(po.groups[0].name.indexOf("（")+1,po.groups[0].name.lastIndexOf("）"));
			//var lastTitle = po.groups[4].name.substring(po.groups[4].name.indexOf("（")+1,po.groups[4].name.indexOf("）"));
			$("#subject_title_1 span").text(firstTitle + "科目");
			//$("#subject_title_2 span").text(lastTitle + "科目");			
			//大题标题
			var glen = po.groups.length;
			for(var j=0;j< glen;j++){
				if(type == 1){
					if(po.groups[j].no <= 4){
						//大题标题
						var $gtitle = $('<p><a href="#">&nbsp;&nbsp;'+po.groups[j].name.substring(0,po.groups[j].name.indexOf("（"))+'</a></p>');
						//绑定大题标题点击事件
						// $gtitle.children('a').click(function(e) {
							// var $this = $(this);
							// //右边图标切换
							// $this.closest('p').toggleClass('hide');
							// //小题区域显示隐藏切换
							// $this.closest('li').find('.subitem').slideToggle();
						// });
						//本大题下小题区域
						//var $itdiv = $('<div class="subitem"></div>');
						
						var dtno = po.groups[j].no;
						var itlen = po.groups[j].itemCodes.length;
						for(var k=0;k< itlen;k++){
							var icode = po.groups[j].itemCodes[k];
							//小题对象，根据小题code从itemMap中获得数组指针，然后再得到真实的对象
							var ito = po.items[po.itemMap[icode]];
							//console.log(JSON.stringify(i));
							//只有顶级小题才有导航
							if(ito.level > 0)
								continue;
							//小题按钮
							//var $itbtn = $('<a href="#IT-'+ito.code+'" class="navs" style="text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px;">'+ito.name+'&nbsp;</a>');


							// kmtype = OBT.storage.getSession("kmtype");

                            var $itbtn = $('<a id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                            if (kmtype==1) {
                                if (dtno == 2) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'JS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 7 || dtno == 8) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }
                            } else if (kmtype==2) {
                               if (dtno == 3 || dtno == 4) {
									if(ito.code == 'YBS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								} else if (dtno == 7 || dtno == 8) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								} 
                            }else if (kmtype==3) {
                                if (dtno == 2) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'QE') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 7 || dtno == 8) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }
                            } else if (kmtype==4) {
                                if (dtno == 2) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'YSW') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 7 || dtno == 8) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }
                            } 

							//当前小题
							if(icode == progress[po.code]){
							    $itbtn.addClass('active');
							}
							//小题标记
							//****************************************************************************************
							if(ito.flag==1) {
									$('#testflag').get(0).checked = true;

								if(ito.type ==='COMPOSITE'){
									var fdone = true;
									for(var m=0;m<ito.childrens.length;m++){
										var cito = OBT.paper.getItem(ito.childrens[m]);
										if(cito &&( cito.answer.length==0||parseInt(cito.answer)==0)){
											fdone = false;
											break;
										}
									}
									if (fdone) {
										$itbtn.children('span').remove();
										$itbtn.append(settings.flag);
										$itbtn.addClass("green1");
									} else {
										$itbtn.children('span').remove();
										$itbtn.append(settings.flagNoans);
										
										$itbtn.removeClass("green1");
									}
									
								} else {
									if (ito.answer == "" || ito.answer == 0) {
										$itbtn.append(settings.flagNoans);
										
									} else {
										$itbtn.append(settings.flag);
									}
									
									//$itbtn.append(settings.flag);
									if(parseInt(ito.answer)>0)
										$itbtn.addClass("green1");
								}
							} else {
								//未作答
								if(ito.type ==='COMPOSITE'){
									
									//复合小题
									var done = true;
									for(var l=0;l<ito.childrens.length;l++){
										var cito = OBT.paper.getItem(po.code,ito.childrens[l]);
										if(cito && (cito.answer.length == 0||parseInt(ito.answer)==0)){
											done = false;
											break;
										}
									}
									if(!done){
										$itbtn.append(settings.noans);
									} else {
										$itbtn.addClass("green1");
									}
									
								}else{
									if(ito.answer.length ==0||parseInt(ito.answer)==0)
										$itbtn.append(settings.noans);
									else
										$itbtn.addClass("green1");
								}
							}
							//绑定小题点击事件
							$itbtn.bind('click', ito, function(e) {
								//发布当前小题事件
								var curito = OBT.paper.getCurItem();
								$.publish(OBT.EVENT_ITEM_CHANGING,[curito,e.data]);
								var code = this.innerHTML;
								code = code.substring(0,code.indexOf("&")).split("-")[0];
								$(".paperTitle").remove();
								/**if(kmtype == 1){
									if (0 < code && code <= 78)
										$(".single").text($("#subject_title_1 span").text()+" >> A1题型");
									else if (78 < code && code <= 80)
										$(".single").text($("#subject_title_1 span").text()+" >> A2题型");
									else if (80 < code && code <= 83)
										$(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
									else if (83 < code && code <= 100)
										$(".single").text($("#subject_title_1 span").text()+" >> B1题型");
								}else if(kmtype == 2){
									if (0 < code && code <= 65)
										$(".single").text($("#subject_title_1 span").text()+" >> A1题型");
									else if (65 < code && code <= 76)
										$(".single").text($("#subject_title_1 span").text()+" >> A2题型");
									else if (76 < code && code <= 82)
										$(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
									else if (82 < code && code < 100)
										$(".single").text($("#subject_title_1 span").text()+" >> B1题型");
								}else if(kmtype == 3){
									if (0 < code && code <= 60)
										$(".single").text($("#subject_title_1 span").text()+" >> A1题型");
									else if (60 < code && code <= 72)
										$(".single").text($("#subject_title_1 span").text()+" >> A2题型");
									else if (72 < code && code <= 87)
										$(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
									else if (87 < code && code < 100)
										$(".single").text($("#subject_title_1 span").text()+" >> B1题型");
								}else if(kmtype == 4){
									if (0 < code && code <= 28)
										$(".single").text($("#subject_title_1 span").text()+" >> A1题型");
									else if (28 < code && code <= 57)
										$(".single").text($("#subject_title_1 span").text()+" >> A2题型");
									else if (57 < code && code <= 92)
										$(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
									else if (92 < code && code < 200)
										$(".single").text($("#subject_title_1 span").text()+" >> B1题型");
								}**/
							});//end 小题生成
							//增加到小题区域中
							$itdiv.append($itbtn);
						}//end 大题生成
						//合并到试卷中
						//$pul.append($('<li></li>').append($gtitle).append($itdiv));
						$pul.append($itdiv);
					}
				}else{
					
					if(po.groups[j].no > 4){						
						//大题标题
						var $gtitle = $('<p><a href="#">&nbsp;&nbsp;'+po.groups[j].name.substring(0,po.groups[j].name.indexOf("（"))+'</a></p>');
						//绑定大题标题点击事件
						// $gtitle.children('a').click(function(e) {
							// var $this = $(this);
							// //右边图标切换
							// $this.closest('p').toggleClass('hide');
							// //小题区域显示隐藏切换
							// $this.closest('li').find('.subitem').slideToggle();
						// });
						//本大题下小题区域
						var $itdiv = $('<div class="subitem"></div>');
						
						var dtno = po.groups[j].no;
						var itlen = po.groups[j].itemCodes.length;
						for(var k=0;k< itlen;k++){
							var icode = po.groups[j].itemCodes[k];
							//小题对象，根据小题code从itemMap中获得数组指针，然后再得到真实的对象
							var ito = po.items[po.itemMap[icode]];
							//console.log(JSON.stringify(i));
							//只有顶级小题才有导航
							if(ito.level > 0)
								continue;
							//小题按钮
							//var $itbtn = $('<a href="#IT-'+ito.code+'" class="navs" style="text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px;">'+ito.name+'&nbsp;</a>');

								
							//var kmtype = OBT.storage.getSession("kmtype");
							
							var $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
							if (kmtype==1) {
								if (dtno == 2) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								}  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'JS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								}  else if (dtno == 7 || dtno == 8) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:700px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								}
							} else if (kmtype==2) {
								if (dtno == 3 || dtno == 4) {
									if(ito.code == 'JS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								} else if (dtno == 7 || dtno == 8) {
									$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
								} 
							}else if (kmtype==3) {
                                if (dtno == 2) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'JS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 7 || dtno == 8) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }
                            } else if (kmtype==4) {
                                if (dtno == 2) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:30px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 3 || dtno == 4) {
									if(ito.code == 'JS') {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:58px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									} else {
										$itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:52px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
									}
                                    
                                } else if (dtno == 5||dtno ==6) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:36px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }  else if (dtno == 7 || dtno == 8) {
                                    $itbtn = $('<a  id="IIT-'+ito.code+'" onclick="window.location.href=\"#IT-'+ito.code+'\"" class="navs" style="min-width:70px;text-decoration: none;line-height:35px;padding:3px;margin:3px 2px;border-radius: 3px; cursor:pointer;">'+ito.name+'&nbsp;</a>');
                                }
                            }

							//当前小题
							if(icode == progress[po.code]){
								$itbtn.addClass('active');
							}
							//小题标记
							//****************************************************************************************
							if(ito.flag==1) {
								$('#testflag').get(0).checked = true;

								if(ito.type ==='COMPOSITE'){
									var fdone = true;
									for(var m=0;m<ito.childrens.length;m++){
										var cito = OBT.paper.getItem(ito.childrens[m]);
										if(cito &&( cito.answer.length==0||parseInt(cito.answer)==0)){
											fdone = false;
											break;
										}
									}
									if (fdone) {
										$itbtn.children('span').remove();
										$itbtn.append(settings.flag);
										$itbtn.addClass("green1");
									} else {
										$itbtn.children('span').remove();
										$itbtn.append(settings.flagNoans);
									
										$itbtn.removeClass("green1");
									}
									
								} else {
									
									if (ito.answer == "" || ito.answer == 0) {
										$itbtn.append(settings.flagNoans);
										
									} else {
										$itbtn.append(settings.flag);
									}
									
									//$itbtn.append(settings.flag);
									if(parseInt(ito.answer)>0)
										$itbtn.addClass("green1");
								}
								
								
								
							
							} else {
								//未作答
								if(ito.type ==='COMPOSITE'){
									
									//复合小题
									var done = true;
									for(var l=0;l<ito.childrens.length;l++){
										var cito = OBT.paper.getItem(po.code,ito.childrens[l]);
										if(cito && (cito.answer.length == 0||parseInt(ito.answer)==0)){
											done = false;
											break;
										}
									}
									if(!done){
										$itbtn.append(settings.noans);
									} else {
										$itbtn.addClass("green1");
									}
									
								}else{
									if(ito.answer.length ==0||parseInt(ito.answer)==0)
										$itbtn.append(settings.noans);
									else
										$itbtn.addClass("green1");
								}
							}
							//绑定小题点击事件
							$itbtn.bind('click', ito, function(e) {								
								//发布当前小题事件
								var curito = OBT.paper.getCurItem();
								$.publish(OBT.EVENT_ITEM_CHANGING,[curito,e.data]);
								var code = this.innerHTML;
								code = code.substring(0,code.indexOf("&")).split("-")[0];
								$(".paperTitle").remove();
								/**
								if(kmtype == 1){
									if (100 < code && code <= 165)
										$(".single").text($("#subject_title_2 span").text()+" >> A1题型");
									else if (165 < code && code <= 176)
										$(".single").text($("#subject_title_2 span").text()+" >> A2题型");
									else if (176 < code && code <= 182)
										$(".single").text($("#subject_title_2 span").text()+" >> A3/A4 题型");
									else if (182 < code && code < 200)
										$(".single").text($("#subject_title_2 span").text()+" >> B1题型");
								}else if(kmtype == 2){
									if (100 < code && code <= 128)
										$(".single").text($("#subject_title_2 span").text()+" >> A1题型");
									else if (128 < code && code <= 157)
										$(".single").text($("#subject_title_2 span").text()+" >> A2题型");
									else if (157 < code && code <= 192)
										$(".single").text($("#subject_title_2 span").text()+" >> A3/A4 题型");
									else if (192 < code && code < 200)
										$(".single").text($("#subject_title_2 span").text()+" >> B1题型");
								} **/
								
							});//end 小题生成
							//增加到小题区域中
							$itdiv.append($itbtn);
						}//end 大题生成
						//合并到试卷中
						$pul.append($('<li></li>').append($gtitle).append($itdiv));
					}
				}
			}//end 试卷生成
			$pdiv.append($pul);
		}
		return $pdiv;
	}
	$.fn.ItemNav = function(options){
		var defaults = {
			oround: false,//随机顺序
			cancel: false, //可以取消radio选项
			flag:'<span style="color: red">?</span>',
			flagNoans:'<span style="color: red"><span style="font-size:14px;line-height:24px;vertical-align:top">*</span><span style="font-size:14px;line-height:24px;margin-left:-7px;vertical-align:bottom">?</span></span>',
			noans:'<span style="color: red">*</span>'
		};
		var settings = $.extend({}, defaults, options); //将一个空对象做为第一个参数
		var xtarea = this;
		//科目导航栏
		/*var $stabs = createSubjectDiv(settings);
		if($stabs){
			xtarea.append($stabs);
		}*/
		//试卷小题按钮区
		var $itemdiv = createPaperDiv(settings,options);
		if($itemdiv)
			xtarea.append($itemdiv);
		//处理小题改变事件
		$.subscribe(OBT.EVENT_ITEM_CHANGED, function(_,old,ito){
			//现有小题
			if(old.code == ito.code)
				return false;
			//当前试卷
			var po = OBT.paper.getCurPaper();
			var $paper = $('#P-'+po.code);
			$paper.find('a.active').each(function() {
				$(this).removeClass('active');
			});
			//$paper.find('a[href="#IT-'+ito.code+'"]').addClass('active');
            $paper.find("#IIT-" + ito.code).addClass('active');
		});
		
		//处理小题作答事件，标记已作答
		$.subscribe(OBT.EVENT_ANS_CHANGED, function(_,ito,ans){
			if(parseInt(ito.level) == 0){
				
				//当前试卷
				var po = OBT.paper.getCurPaper();
				var $paper = $('#P-'+po.code);
				//不能移除标记
				if (ito.flag==1 && parseInt(ito.answer)==0) {
					//var $item = $('#P-'+po.code).find('a[href="#IT-'+ito.code+'"]');
					//调试
                    var $item = $('#P-'+po.code).find("#IIT-" + ito.code);
					//调试
					$item.children('span').remove();
					$item.append(settings.flagNoans);
				
					$item.removeClass("green1");
					return;
				} else if (ito.flag==1 && parseInt(ito.answer)!=0) {
					//var $item = $('#P-'+po.code).find('a[href="#IT-'+ito.code+'"]');
                    //调试
                    var $item = $('#P-'+po.code).find("#IIT-" + ito.code);
                    //调试
					$item.children('span').remove();
					$item.append(settings.flag);
					$item.addClass("green1");  
					return;
				} else if (ito.flag!=1 && parseInt(ito.answer)==0) {
					//var $item = $('#P-'+po.code).find('a[href="#IT-'+ito.code+'"]');
                    //调试
                    var $item = $('#P-'+po.code).find("#IIT-" + ito.code);
                    //调试
					$item.children('span').remove();
					
					$item.append(settings.noans);
					
					$item.removeClass("green1");
				} else {
					//var $item = $paper.find('a[href="#IT-'+ito.code+'"]');
                    //调试
                    var $item = $paper.find("#IIT-" + ito.code);
                    //调试
					$item.children('span').remove();
					$item.addClass("green1");
				}
			}else{
				//复合小题处理
				var pito = OBT.paper.getItem(ito.pcode);
				if(pito ==null)
					return;
				
				var done = true;
				for(var i=0;i<pito.childrens.length;i++){
					var cito = OBT.paper.getItem(pito.childrens[i]);
					console.log("chiled answer:"+cito.answer);
					if(cito && (cito.answer.length==0||parseInt(cito.answer)==0)){
						done = false;
						break;
					}
				}
				
				
				if (pito.flag==1 && !done) {
					var po = OBT.paper.getCurPaper();
					var $paper = $('#P-'+po.code);
					//var $item = $paper.find('a[href="#IT-'+pito.code+'"]');
					//调试
                    var $item = $paper.find("#IIT-" + pito.code);
					//调试
					$item.children('span').remove();
					$item.append(settings.flagNoans);
					
					$item.removeClass("green1");
					return;
				} else if (pito.flag==1 && done) {
					var po = OBT.paper.getCurPaper();
					var $paper = $('#P-'+po.code);
					//var $item = $paper.find('a[href="#IT-'+pito.code+'"]');
                    //调试
                    var $item = $paper.find("#IIT-" + pito.code);
                    //调试
					$item.children('span').remove();
					$item.append(settings.flag);
					$item.addClass("green1");
					return;
				} else if (pito.flag!=1 && !done) {
					var po = OBT.paper.getCurPaper();
					var $paper = $('#P-'+po.code);
					//var $item = $paper.find('a[href="#IT-'+pito.code+'"]');
                    //调试
                    var $item = $paper.find("#IIT-" + pito.code);
                    //调试
					$item.children('span').remove();
					
					$item.append(settings.noans);
					
					$item.removeClass("green1");
				} else {
					var po = OBT.paper.getCurPaper();
					var $paper = $('#P-'+po.code);
					//var $item = $paper.find('a[href="#IT-'+pito.code+'"]');
                    //调试
                    var $item = $paper.find("#IIT-" + pito.code);
                    //调试
					$item.children('span').remove();
					$item.addClass("green1");
				}
				
				
				/**if(done){
					var po = OBT.paper.getCurPaper();
					var $paper = $('#P-'+po.code);
					var $item = $paper.find('a[href="#IT-'+pito.code+'"]');
					$item.children('span').remove();
					$item.addClass("green1");
				} else {
					console.log("done["+ done +"]");
					var po = OBT.paper.getCurPaper();
					var $item = $('#P-'+po.code).find('a[href="#IT-'+pito.code+'"]');
					$item.children('span').remove();
					$item.append(settings.noans);
					$item.removeClass("green1");
				}*/
			}
		});
		
		//处理标记更改事件
		$.subscribe(OBT.EVENT_FLAG_CHANGED, function(_,ito){
			//当前试卷
			var po = OBT.paper.getCurPaper();
			//var $item = $('#P-'+po.code).find('a[href="#IT-'+ito.code+'"]');
			//调试
            var $item = $('#P-'+po.code).find("#IIT-" + ito.code);
			//调试
			$item.children('span').remove();
			if(ito.flag==1) {
				if(ito.type ==='COMPOSITE'){
					//复合小题
					var done = true;
					for(var i=0;i<ito.childrens.length;i++){
						var cito = OBT.paper.getItem(ito.childrens[i]);
						if(cito &&( cito.answer.length==0||parseInt(cito.answer)==0)){
							done = false;
							break;
						}
					}
					if (ito.flag==1 && !done) {
						
						$item.children('span').remove();
						$item.append(settings.flagNoans);
					
						$item.removeClass("green1");
						return;
					} else if (ito.flag==1 && done) {
						
						$item.children('span').remove();
						$item.append(settings.flag);
						$item.addClass("green1");
						return;
					} else if (ito.flag!=1 && !done) {
						
						$item.children('span').remove();
						
						$item.append(settings.noans);
						
						$item.removeClass("green1");
					} else {
						
						$item.children('span').remove();
						$item.addClass("green1");
					}
				
				}else{
					if (ito.answer == "" || ito.answer == 0) {
						$item.append(settings.flagNoans);
					
					} else {
						$item.append(settings.flag);
					}
				}
				
			} else {
				if(ito.type ==='COMPOSITE'){
					//复合小题
					var done = true;
					for(var i=0;i<ito.childrens.length;i++){
						var cito = OBT.paper.getItem(ito.childrens[i]);
						if(cito &&( cito.answer.length==0||parseInt(cito.answer)==0)){
							done = false;
							break;
						}
					}
					if(!done){
						$item.append(settings.noans);
					}
				}else{
					if(ito.answer.length ==0||parseInt(ito.answer)==0)
						$item.append(settings.noans);
				}
			}
		});
	}
	// 行排列导航条
	$.fn.ItemLine = function(options) {
		var defaults = {
			oround: false,//随机顺序
			cancel: false //可以取消radio选项
		};
		var settings = $.extend({}, defaults, options); //将一个空对象做为第一个参数
		var xtline = this;
		xtline.navline({
　　    items: OBT.paper.getCurPaper().itArray.length,
			displayedPages: 10,
			currentPage:OBT.getCurItemIdx() +1,
			onPageClick:function(i, event){
				//设置当前小题，该插件的页码从1开始，而不是0开始
				var item = OBT.setCurItemIdx(i -1);
				//发布当前小题事件
				$.publish('CUR-ITEM-CHANGED',[item]);
			}
　　 });
		//绑定当前小题变更事件
		$.subscribe('CUR-ITEM-CHANGED', function(_,it){
			xtline.navline('drawPage',it.idx +1);
		});
	}
	//上一题
	$.fn.PrevButton = function(options){
		var $this = $(this);
		//第一小题时，禁用当前按钮
		var ito = OBT.paper.getPrevItem();
		if(ito){
			$this.removeAttr('disabled');
			$this.css('color','');
		}else{
			$this.attr('disabled',true);
			$this.css('color','#fff');
		}

		//绑定按钮点击事件
		$this.bind("click",function(e){
			var curito = OBT.paper.getCurItem();
			var previto = OBT.paper.getPrevItem();
			if(curito.type == "COMPOSITE" && OBT.paper.getPrevSubItems()){
				var prevSubItem = OBT.paper.getPrevSubItems();
				itemSubTitleClick(prevSubItem.code);
                return;
                /*//调试
				console.log("previto last children: " + previto.childrens[previto.childrens.length - 1]);
                //如果上一小题带有子小题，那么切换到上一小题的最后一个子小题
				if(previto.type == "COMPOSITE" || prevSubItem == null){
					//获取上一小题的最后一个子小题Code
					var previtoLastChildrenCode = previto.childrens[previto.childrens.length - 1];
                    //发布当前小题改变中事件
                    $.publish(OBT.EVENT_ITEM_CHANGING,[curito,previto]);
					//处理小题改变事件
                    $.subscribe(OBT.EVENT_ITEM_CHANGED, function(_,old,ito){
                        //第一小题时，禁用当前按钮
                        if(previto){
                            $this.removeAttr('disabled');
                            $this.css('color','');
                        }else{
                            $this.attr('disabled',true);
                            $this.css('color','#FFF');
                        }
                        //更新连接
                        if($this.is('a')){
                            $this.attr('href','#IT-' + previto.code );
                        }
                    });
					itemSubTitleClick(previtoLastChildrenCode);
					return;
				}
				//调试*/


			}

			var ito = OBT.paper.getPrevItem();
			if(ito == null){
				return;
			}
			if(ito.name.split("-")[0] <= 100){
				showSubject(1);
			}else{
				showSubject(2);
			}
			
			
			//OBT.storage.removeSession('subItem');
			
			//发布当前小题改变中事件
			
			$.publish(OBT.EVENT_ITEM_CHANGING,[curito,ito]);
			var code = ito.name.split("-")[0];
			$(".paperTitle").remove();
			
			/**
			if(kmtype == 1){
                if (0 < code && code <= 78)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (84 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (79 <= code && code <= 80)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (code == 81)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
                
                console.log("题目切换code(kmtype=1)：" + code);
			}else if(kmtype == 2){
                if (0 < code && code <= 65)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (83 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (66 <= code && code <= 76)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (77 <= code && code <= 82)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
                
                console.log("题目切换code(kmtype=2)：" + code);
			}else if(kmtype == 3){
                if (0 < code && code <= 60)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (88 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (61 <= code && code <= 72)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (73 <= code && code <= 87)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
				console.log("题目切换code(kmtype=3)：" + code);
			}else if(kmtype == 4){
                if (0 < code && code <= 28)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (93 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (29 <= code && code <= 57)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (58 <= code && code <= 92)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
				console.log("题目切换code(kmtype=4)：" + code);
			} **/
			document.getElementById("IIT-"+ ito.code +"").scrollIntoView(false);
			
		});
		//处理小题改变事件
		$.subscribe(OBT.EVENT_ITEM_CHANGED, function(_,old,ito){
			//第一小题时，禁用当前按钮
			var preito = OBT.paper.getPrevItem();
			if(preito){
				$this.removeAttr('disabled');
				$this.css('color','');
			}else{
				$this.attr('disabled',true);
				$this.css('color','#FFF');
			}
			//更新连接
			if($this.is('a')){
				$this.attr('href','#IT-' + preito.code );
			}
		});
	}
	//下一题
	$.fn.NextButton = function(){
		var $this = $(this);
		//最后一题时，禁用当前按钮
		var ito = OBT.paper.getNextItem();
		if(ito){
			$this.removeAttr('disabled');
			$this.css('color','');
		}else{
			$this.attr('disabled',true);
			$this.css('color','#fff');
		}

		//绑定按钮点击事件
		$this.bind("click",function(e){
			var curito = OBT.paper.getCurItem();
			if(curito.type == "COMPOSITE" && OBT.paper.getNextSubItems()) {
				var nextSubItem = OBT.paper.getNextSubItems();
				itemSubTitleClick(nextSubItem.code);
				return ;
			}
			
			var ito = OBT.paper.getNextItem();
			if(ito ==null){
				return;
			}
			if(ito.name.split("-")[0] <= 100){
				showSubject(1);
			}else{
				showSubject(2);
			}

			
			//发布当前小题改变中事件
			
			$.publish(OBT.EVENT_ITEM_CHANGING,[curito,ito]);
			
			var code = ito.name.split("-")[0];
			$(".paperTitle").remove();
			/**
			if(kmtype == 1){
                if (0 < code && code <= 78)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (84 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (79 <= code && code <= 80)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (code == 81)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
                
                console.log("题目切换code(kmtype=1)：" + code);
			}else if(kmtype == 2){
                if (0 < code && code <= 65)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (83 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (66 <= code && code <= 76)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (77 <= code && code <= 82)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
                
                console.log("题目切换code(kmtype=2)：" + code);
			}else if(kmtype == 3){
                if (0 < code && code <= 60)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (88 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (61 <= code && code <= 72)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (73 <= code && code <= 87)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
				console.log("题目切换code(kmtype=3)：" + code);
			}else if(kmtype == 4){
                if (0 < code && code <= 28)
                    $(".single").text($("#subject_title_1 span").text()+" >> A1题型");
                else if (93 <= code && code <= 99)
                    $(".single").text($("#subject_title_1 span").text()+" >> B1题型");
                else if (29 <= code && code <= 57)
                    $(".single").text($("#subject_title_1 span").text()+" >> A2题型");
                else if (58 <= code && code <= 92)
                    $(".single").text($("#subject_title_1 span").text()+" >> A3/A4 题型");
				console.log("题目切换code(kmtype=4)：" + code);
			}
			**/
			document.getElementById("IIT-"+ ito.code +"").scrollIntoView(false);
			
		});
	
		//处理小题改变事件
		$.subscribe(OBT.EVENT_ITEM_CHANGED, function(_,old,ito){
			//最后一题时，禁用当前按钮
			var nextito = OBT.paper.getNextItem();
			if(nextito){
				$this.removeAttr('disabled');
				$this.css('color','');
			}
			else{
				//最后一题带有子小题时，允许切换子小题
				if(OBT.storage.getSession('subItem') == null){
                	return;
				}
				else if(JSON.parse(OBT.storage.getSession('subItem')).code == 199 || 200){
					return;
				}
				//否则禁止点击下一题按钮
				else{
                    $this.attr('disabled',true);
                    $this.css('color','#FFF');
				}
			}
			//更新连接
			if($this.is('a')){
				$this.attr('href','#IT-'+nextito.code );
			}
		});
	}
})(jQuery, window, document);